package com.wesley.controller;

import com.wesley.feign.TestServer2Feign;
import com.wesley.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * created by wei xin on 2020/3/3 0003
 */
@Controller
@RequestMapping("/server1")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private LoadBalancerClient balancerClient;

    @RequestMapping("/test1")
    @ResponseBody
    public String test1() {
        System.out.println("2321321321");
        userService.saveUser("weixin");
        return "hello world";
    }


    @RequestMapping("/showMsg")
    @ResponseBody
    public Map showMsg() {
        ServiceInstance si = balancerClient.choose("test-server2");

        System.out.println(si.getHost() +"--" + si.getPort() + "=" +si.getUri());

        return userService.showMsg();
    }


    @RequestMapping("/showMsg2")
    @ResponseBody
    public Map showMsg2() {
        Map map = new HashMap();
        map.put("msg", "hello world");
        return map;
    }



}
